package br.edu.com1263.dao;

import java.util.Collection;

import javax.persistence.Query;

import br.edu.com1263.model.Aluno;
import br.edu.com1263.model.Turma;

public class TurmaDAOImpl extends AbstractDAO implements TurmaDAO{
	
	public TurmaDAOImpl(){

}

	

	@Override
	public Collection<Turma> consultarTodos() {
		Query query = manager.createQuery("SELECT t FROM Turma t");
		return query.getResultList();
	}

	@Override
	public void salvar(Turma turma) {
		manager.persist(turma);
		
	}
	
	
	public void alterar(Turma turma) {
		manager.merge(turma);
	}
    
    public void remover(Turma turma) {
		manager.remove(turma);
	}

	@Override
	public Turma consultar(Long id) {
		return manager.find(Turma.class, id);
	}



	@Override
	public Collection<Turma> consultarProfessor(Long idProfessor) {
		Query query = manager.createQuery("SELECT t FROM Turma t WHERE t.professor.id = :idProfessor");
		query.setParameter("idProfessor", idProfessor);
		
		return query.getResultList();
	}

}
